//
//  LHXBtnMenusViewController.m
//  Etwo
//
//  Created by 林浩翔 on 16/6/19.
//  Copyright © 2016年 林浩翔. All rights reserved.
//

#import "LHXBtnMenusViewController.h"
#import "LHXMainBtnItem.h"
#import "LHXBtnItem.h"

#define menusBtnWH 45


@interface LHXBtnMenusViewController ()

@property(strong,nonatomic)NSArray *btnTitleArray;

@property(strong,nonatomic)NSMutableArray *btnArray;



@end

@implementation LHXBtnMenusViewController

- (NSArray *)btnTitleArray{
    if (_btnTitleArray == nil) {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"MainBtn" ofType:@"plist"];
        NSArray *BtnItemArray = [NSArray arrayWithContentsOfFile:plistPath];
        LHXMainBtnItem *MainItem = [LHXMainBtnItem MainItemWithArray:BtnItemArray];
        NSMutableArray *tempArray = [NSMutableArray array];
        for (NSDictionary *dict in MainItem.BtnMenusViewBtnItem) { // 遍历字典数组中的每一个字典
            // 将字典 转为 模型
            LHXBtnItem *btnItem = [LHXBtnItem itemWithDict:dict];
            
            [tempArray addObject:btnItem];
        }
        _btnTitleArray = tempArray;
        
    }
    return _btnTitleArray;
}

-(NSMutableArray *)btnArray{
    if (_btnArray == nil) {
        _btnArray = [NSMutableArray array];
    }
    return _btnArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor clearColor];
    // Do any additional setup after loading the view.
    
    [self setMenusBtn];
}

- (void)setMenusBtn{
    
    
    UIView *btnView = [[UIView alloc]init];
    btnView.frame = self.view.frame;
    
    [self.view addSubview:btnView];
    
    
    for (int i = 0; i < self.btnTitleArray.count; i++) {
        LHXbutton *btn = [LHXbutton btn];
        
        btn.item = self.btnTitleArray[i];
        
        btn.alpha = 1;
        
        btn.btnTitle.font = [UIFont systemFontOfSize:13];
        
        if ([btn.btnTextTag isEqualToString:self.disenbleBtnName]) {
            btn.enabled = NO;
        }
        
        btn.frame = CGRectMake(5,(menusBtnWH + 5)*i, menusBtnWH, menusBtnWH);
        
        [btn addTarget:self action:@selector(menusClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [btnView addSubview:btn];
        
        [self.btnArray addObject:btn];
    }
}

- (void)menusClick:(LHXbutton *)btn{
    
    if ([btn.btnTitle.text isEqualToString:@"主页"]) {
        //发送通知
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LHXMainView" object:self];
    }else if([btn.btnTitle.text isEqualToString:@"裁剪\n工具"]){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LHXCutView" object:self];
    }else if([btn.btnTitle.text isEqualToString:@"文字\n工具"]){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LHXWritingView" object:self];
    }
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//状态栏设为白色
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
};

@end
